function TagBox(ele) {
	var self = this;
	this.$ele = ele;
	this.$tagContainer = $('.tag-container',self.$ele);
	this.$selectableTagContainer = $('.selectable-tag-box',self.$ele);
	this._initTags();
	this._initCheckbox(this);
}

TagBox.prototype = {
	constructor: TagBox,
	$ele: null,
	$tagContainer: null,
	$selectableTagContainer: null,
	setChecks: function(checkedIdArr) {
		for ( var index in checkedIdArr) {
			$('input[data-tag-id="'+ checkedIdArr[index] +'"').iCheck('check');
		}
	},
	reset: function() {
		$('input',this.$ele).iCheck('uncheck');
	},
	getCheckedTagIdArray: function() {
		var resultArray = [];
		$('input:checked',this.$selectableTagContainer).each(function(){
			var $this = $(this);
			resultArray.push($this.attr('data-tag-id'));
		});
		return resultArray;
	},
	_initTags: function() {
		$('.tag-container',this.$ele).on('click','a',function(){
			var $self = $(this);
			var tagId = $self.attr('data-tag-id'); 
			$('input[data-tag-id="'+tagId+'"').iCheck('uncheck');
		});
   },
	_initCheckbox: function(instance) {
		$('input').iCheck({
			checkboxClass: 'icheckbox_flat-orange',
			radioClass: 'iradio_flat-orange'
		});
		$('input',self.$selectableTagContainer).on('ifChecked',function(evt){
			var $this = $(this);
			var $tag = $('<a class="label label-primary" title="点击删除" data-tag-id="'+$this.attr('data-tag-id')+'">'+$this.parent().next('label').text()+'<span class="fa fa-times"></span></a>');
			instance.$tagContainer.append($tag);
		}).on('ifUnchecked',function(evt){
			var id = $(evt.target).attr('data-tag-id');
			$('[data-tag-id="'+id+'"]',instance.$tagContainer).remove();
		});
	},
};
